{{ $thisSection  := .CurrentSection.RelPermalink }}
{{ $thisPage     := .RelPermalink }}
{{ $docsSections := where site.Sections "Section" "docs" }}
{{ $version      := index (split .File.Path "/") 1 }}

<aside class="menu">
  <p class="menu-label">
    <a href="/docs/{{ $version }}">
      Harbor version {{ $version }}
    </a>
  </p>

  {{ range $docsSections }}
  {{ range .Sections }} <!-- all docs versions -->
  {{ $thisVersion := index (split .File.Path "/") 1 }}
  {{ if eq $thisVersion $version }} <!-- version filter -->
  {{ range .Sections }} <!-- sections within version -->
  {{ $isThisPage := eq .RelPermalink $thisPage }}
  {{ $showSection := in $thisSection .RelPermalink }}

  <p class="menu-label">
    <a{{ if $isThisPage }} class="has-text-weight-bold"{{ end }} href="{{ .RelPermalink }}">
      {{ .Title }}
    </a>
  </p>

  {{ if $showSection }}
  <ul class="menu-list">
    {{ range .Sections }}
    {{ $showSection := in $thisSection .RelPermalink }}
    {{ $isThisPage := eq .RelPermalink $thisPage }}
    <li>
      <a{{ if $isThisPage }} class="is-active"{{ end }} href="{{ .RelPermalink }}">
        {{ .Title }}
      </a>

      {{ with .RegularPages }}
      {{ if $showSection }}
      <ul>
        {{ range . }}
        {{ $isThisPage := eq .RelPermalink $thisPage }}
        <li>
          <a{{ if $isThisPage }} class="is-active"{{ end }} href="{{ .RelPermalink }}">
            {{ .Title }}
          </a>
        </li>
        {{ end }}
      </ul>
      {{ end }}
      {{ end }}
    </li>
    {{ end }}

    {{ range .RegularPages }}
    {{ $isThisPage := eq $thisPage .RelPermalink }}

    <li>
      <a{{ if $isThisPage }} class="has-text-weight-bold is-active"{{ end }} href="{{ .RelPermalink }}">
        {{ .Title }}
      </a>
    </li>
    {{ end }}
  </ul>
  {{ end }}

  {{ end }}
  {{ end }}
  {{ end }}
  {{ end }}
</aside>
